package com.vilen.retrofit2helloworld_1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import com.vilen.retrofit2helloworld_1.api.ApiBasic;
import java.io.IOException;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

/**
 * 最简单的 retrofit2
 */
public class MainActivity extends AppCompatActivity {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Retrofit retrofit = new Retrofit.Builder().baseUrl("http://36.107.183.80:8080/").build();
    ApiBasic apiBasic = retrofit.create(ApiBasic.class);
    Call<ResponseBody> call = apiBasic.getUserList();

    call.enqueue(new Callback<ResponseBody>() {
      @Override public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
        try {
          Log.i("CHX", "response=" + response.body().string());
        } catch (IOException e) {
          e.printStackTrace();
        }
      }

      @Override public void onFailure(Call<ResponseBody> call, Throwable t) {
        Log.i("CHX", "onFailure=" + t.getMessage());
      }
    });
  }
}
